<div id="prefaceContainer" class="preface">
<?php
	$_GET['prefix'] = 'ctg';
	include 'lib/php/load.php';
	ob_end_clean();
	$buttons = $items;
	$btn_coords = array();
	$i = 0;
	foreach ($buttons as $id => $item) {
		displayCtg($id, $item, false);
		array_push($btn_coords, "$item[start_x]$item[start_y]");
		$i++;
	}
	
	$_GET['prefix'] = 'btn';
	$_GET['ctg_id'] = 0;
	include 'lib/php/load.php';
	ob_end_clean();
	$buttons = $items;
	$i = 0;
	foreach ($buttons as $id => $item) {
		if(isset($_GET['btn_id'])) {
			if($id == $_GET['btn_id']) {
				displayBtn($id, $item, true);
			} else {
				displayBtn($id, $item, false);
			}
		} else {
			displayBtn($id, $item, false);
		}
		array_push($btn_coords, "$item[x]$item[y]");
		$i++;
	}
	echo '<div id="dummies">';
	for($x=0; $x < 6; $x++) {
		for($y=0; $y < 6; $y++) {
			if(!in_array("$x$y", $btn_coords)) {
				echo "<div id='dummy_$x$y' class=\"dummy item\" style=\"left: ".(80*$x)."px; top: ".(80*$y)."px; z-index: 0;\"></div>\n";
			}
		}
	}
	echo '</div>';
?>
</div>

<?php 
function displayCtg($id, $item, $active){
	$prefix = $item[prefix];
	$div_id = $prefix."_".$id;
	$class = $active == true ? 'item ctg active' : 'item ctg';
	$alias = $item[alias];
	$label = $item[label];
	$thumb = $item[thumb];
	$thumb_enable = $item[thumb_enable];
	$left = 80*$item[start_x];
	$top = 80*$item[start_y];
	$html = array("<div id=\"$div_id\" class=\"$class\" style=\"left:".$left."px; top:".$top."px;\">
	<a id=\"innerlink_$div_id\" class=\"link\" href=\"index.php?prefix=$prefix&amp;ctg_id=$id\"></a>\n");
	if($label != "") 					array_push($html, "	<div id=\"label_$div_id\" class=\"label\">$label</div>\n");
	if($thumb != "" && $thumb_enable) 	array_push($html, "	<img id=\"thumb_$div_id\" class=\"thumb\" src=\"$thumb\" alt=\"$alias\" width=\"73\" height=\"73\" />\n");
	array_push($html, "</div>");
	echo join('', $html);
}
function displayBtn($id, $item, $active) {
	$interactive = $item[interactive];
	$active = $interactive == true ? $active : true;
	$prefix = $item[prefix];
	$div_id = $prefix."_".$id;
	$class = $active == true ? "item btn active" : "item btn";
	$alias = $item[alias];
	$label = $item[label];
	$thumb = $item[thumb];
	$thumb_enable = $item[thumb_enable];
	$link = $item[link];
	$link_enable = $item[link_enable];
	$text = $item[text];
	$text_enable = $item[text_enable];
	$img = $item[img];
	$img_enable = $item[img_enable];
	$ctg = $item[category_id];
	$prj = $item[project_id];
	$site_link = $active == false ? "index.php?prefix=$item[prefix]&amp;ctg_id=$ctg&amp;prj_id=$prj&amp;btn_id=$id" : "index.php?prefix=$item[prefix]&amp;ctg_id=$ctg&amp;prj_id=$prj";
	$x = $active == false ? 80*$item[x] : 80*$item[content_x];
	$y = $active == false ? 80*$item[y] : 80*$item[content_y];
	$width = $active == false ? 73 : 80*$item[content_width]-7;
	$height = $active == false ? 73 : 80*$item[content_height]-7;
	$z = $active == true ? 99 : 0;
	$cursor = $interactive == true ? 'cursor: pointer;' : '';
	if($label != "" || $thumb != "") $bg = "background: #232323;";
	else $bg = "";
	
	$html = array("<div id=\"btn_$id\" class=\"$class\" style=\"left:".$x."px; top:".$y."px; width: ".$width."px; height: ".$height."px; z-index: $z; $bg $cursor\">\n");
	if($interactive) array_push($html, "	<a id=\"innerlink_$div_id\" class=\"link inner\" href=\"$site_link\"></a>\n");
	else if(!empty($link) && $link_enable) array_push($html, "	<a id=\"outerlink_$div_id\" class=\"link outer\" href=\"$link\" target=\"_blank\"></a>\n");
	if($label != "") 					array_push($html, "	<div id=\"label_$div_id\" class=\"label\">$label</div>\n");
	if($thumb != "" && $thumb_enable) 	array_push($html, "	<img id=\"thumb_$div_id\" class=\"thumb\" src=\"$thumb\" alt=\"$alias\" width=\"73\" height=\"73\" />\n");
	if($text != "" && $text_enable) 	array_push($html, "	<div id=\"text_$div_id\" class=\"text\" >$text</div>\n");
	if($img != "" && $img_enable) 		array_push($html, "	<img id=\"img_$div_id\" class=\"img\" src=\"$img\" alt=\"$alias\" width=\"".(80*$item[content_width]-7)."\" height=\"".(80*$item[content_height]-7)."\" />\n");
	array_push($html, "</div>\n");
	echo join('', $html);
}
?>